package com.ypinkj.app.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ypinkj.app.entity.CCompany;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author LF
 * @since 2020-09-29
 */
@Mapper
public interface CCompanyMapper extends BaseMapper<CCompany> {

    @Select("select *  from c_company where companylogin = #{companylogin}")
    CCompany findByName(String companylogin);

    @Select("select *  from c_company where companyname = #{companyname}")
    CCompany findByLoginName(String companyname);

    @Update("<script>" +
            " update c_company" +
            " <set>" +
            " <if test='company.token != null'>" +
            "  token = #{company.token}," +
            " </if>" +
            " <if test='company.updateTime != null'>" +
            "  updateTime=#{company.updateTime}," +
            " </if>" +
            " <if test='company.firstLogin != null'>" +
            "  firstLogin=#{company.firstLogin}," +
            " </if>" +
            " </set>" +
            " where id =" +
            " #{company.id}" +
            " </script>")
    void UpdateUserToken(@Param("company") CCompany company);

    @Select("select *  from c_company where phone = #{phone}")
    CCompany findByPhone(String phone);

    @Update("<script>" +
            " update c_company" +
            " <set>" +
            " <if test='company.token != null'>" +
            "  token = #{company.token}," +
            " </if>" +
            " <if test='company.updateTime != null'>" +
            "  updateTime=#{company.updateTime}," +
            " </if>" +
            " </set>" +
            " where id =" +
            " #{company.id}" +
            " </script>")
    int layout(@Param("company") CCompany company);

    List<CCompany> getPopularCompanies(@Param("page") Integer page,@Param("limit") Integer limit);
}
